//% color="#FA8072" iconWidth=50 iconHeight=40
namespace DFRobot_I2C_RGB{

    //% block="DFRobot_I2C_RGB Init [ADDR]   " blockType="command" 
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    export function DFRobot_I2C_RGBInit(parameter: any, block: any) {
        let addr = parameter.ADDR.code;
  
        Generator.addInclude("DFRobot_I2C_RGBInit", "#include <DFRobot_RGBButton.h>");
        
        Generator.addObject(`DFRobot_I2C_RGBInit${addr}`,"DFRobot_RGBButton",`RGBButton_${addr}(&Wire, ${addr});`);

        Generator.addCode(`while(!RGBButton_${addr}.begin()){};`);

    }
   
    //% block="DFRobot_I2C_RGBsetRGBColor1[ADDR][R][G][B]" blockType="command" 
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    //% R.shadow="number" R.defl="255"
    //% G.shadow="number" G.defl="255"
    //% B.shadow="number" B.defl="255"
    export function DFRobot_I2C_RGBsetRGBColor1(parameter: any, block: any) { 
        let addr = parameter.ADDR.code;
        let r=parameter.R.code;
        let g=parameter.G.code;
        let b=parameter.B.code;
       
             
            Generator.addCode(`RGBButton_${addr}.setRGBColor(${r},${g},${b});`);

       }
    //% externalFunc
    export function getColorsFunc_() {
        return [
            `#FF0000`, "#FF7F00", "#FFFF00", "#00FF00", "#00FFFF", "#0000FF", "#8B00FF", "#FFFFFF","#000000"
        ]
    }

    //% block="设置[ADDR]颜色2 [COLOR] " blockType="command"
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    //% COLOR.shadow="colorPalette" COLOR.params.column=3
    //% COLOR.params.colorsFunc="getColorsFunc_"
    export function DFRobot_I2C_RGBsetRGBColor(parameter: any, block: any) {
        let color = parameter.COLOR.code;
        let addr = parameter.ADDR.code;
      
            if(`${color}` === '0xFF0000'){
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eRed);`);
            }
            else if(`${color}` === '0xFF7F00'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eOrange);`);
            }
            else if(`${color}` === '0xFFFF00'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eYellow);`);
            }
            else if(`${color}` === '0x00FF00'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eGreen);`);
            }
            else if(`${color}` === '0x00FFFF'){

                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eCyan);`);
            }
            else if(`${color}` === '0x0000FF'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eBlue);`);
            }
            else if(`${color}` === '0x8B00FF'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.ePurple);`);
            }
            else if(`${color}` === '0xFFFFFF'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eWhite);`);
            }
            else if(`${color}` === '0x000000'){
                
                Generator.addCode(`RGBButton_${addr}.setRGBColor(RGBButton_${addr}.eBlack);`);
            } 
            
       
       
    }
    //% block="DFRobot_I2C_RGBgetButtonStatus[ADDR]" blockType="boolean" 
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    export function DFRobot_I2C_RGBgetButtonStatus(parameter: any, block: any) { 
        let addr = parameter.ADDR.code;
        Generator.addCode( [`RGBButton_${addr}.getButtonStatus()`,Generator.ORDER_UNARY_POSTFIX]);
       
    }


 
        
   
   }

   
}